/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: nu uc
 * License Type: Evaluation
 */
package org.testis.orm.classes;

import org.orm.*;

public class T_bed_firmware {
    public T_bed_firmware() {
    }

    public boolean save() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .saveObject(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean delete() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .deleteObject(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean refresh() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .getSession().refresh(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean evict() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .getSession().evict(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean deleteAndDissociate() throws PersistentException {
	try {
	    if (getDevice() != null) {
		getDevice().t_bed_firmware.remove(this);
	    }

	    if (getDeviceMap() != null) {
		getDeviceMap().t_bed_firmware.remove(this);
	    }

	    org.testis.orm.classes.T_bed_dut[] lT_bed_duts = t_bed_dut
		    .toArray();
	    for (int i = 0; i < lT_bed_duts.length; i++) {
		lT_bed_duts[i].setActiveFirmware(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtrees = t_dmap_designtree
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtrees.length; i++) {
		lT_dmap_designtrees[i].setFirmware(null);
	    }
	    return delete();
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean deleteAndDissociate(org.orm.PersistentSession session)
	    throws PersistentException {
	try {
	    if (getDevice() != null) {
		getDevice().t_bed_firmware.remove(this);
	    }

	    if (getDeviceMap() != null) {
		getDeviceMap().t_bed_firmware.remove(this);
	    }

	    org.testis.orm.classes.T_bed_dut[] lT_bed_duts = t_bed_dut
		    .toArray();
	    for (int i = 0; i < lT_bed_duts.length; i++) {
		lT_bed_duts[i].setActiveFirmware(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtrees = t_dmap_designtree
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtrees.length; i++) {
		lT_dmap_designtrees[i].setFirmware(null);
	    }
	    try {
		session.delete(this);
		return true;
	    } catch (Exception e) {
		return false;
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    private java.util.Set this_getSet(int key) {
	if (key == org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_T_BED_DUT) {
	    return ORM_t_bed_dut;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_T_DMAP_DESIGNTREE) {
	    return ORM_t_dmap_designtree;
	}

	return null;
    }

    private void this_setOwner(Object owner, int key) {
	if (key == org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_DEVICE) {
	    this.Device = (org.testis.orm.classes.T_bed_devicedefinitions) owner;
	}

	else if (key == org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_DEVICEMAP) {
	    this.DeviceMap = (org.testis.orm.classes.T_dmap_designtree) owner;
	}
    }

    org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {
	public java.util.Set getSet(int key) {
	    return this_getSet(key);
	}

	public void setOwner(Object owner, int key) {
	    this_setOwner(owner, key);
	}

    };

    private int id;

    private String name;

    private org.testis.orm.classes.T_bed_devicedefinitions Device;

    private org.testis.orm.classes.T_dmap_designtree DeviceMap;

    private String description;

    private java.util.Set ORM_t_bed_dut = new java.util.HashSet();

    private java.util.Set ORM_t_dmap_designtree = new java.util.HashSet();

    private void setId(int value) {
	this.id = value;
    }

    public int getId() {
	return id;
    }

    public int getORMID() {
	return getId();
    }

    public void setName(String value) {
	this.name = value;
    }

    public String getName() {
	return name;
    }

    public void setDescription(String value) {
	this.description = value;
    }

    public String getDescription() {
	return description;
    }

    public void setDevice(
	    org.testis.orm.classes.T_bed_devicedefinitions value) {
	if (Device != null) {
	    Device.t_bed_firmware.remove(this);
	}
	if (value != null) {
	    value.t_bed_firmware.add(this);
	}
    }

    public org.testis.orm.classes.T_bed_devicedefinitions getDevice() {
	return Device;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Device(
	    org.testis.orm.classes.T_bed_devicedefinitions value) {
	this.Device = value;
    }

    private org.testis.orm.classes.T_bed_devicedefinitions getORM_Device() {
	return Device;
    }

    public void setDeviceMap(
	    org.testis.orm.classes.T_dmap_designtree value) {
	if (DeviceMap != null) {
	    DeviceMap.t_bed_firmware.remove(this);
	}
	if (value != null) {
	    value.t_bed_firmware.add(this);
	}
    }

    public org.testis.orm.classes.T_dmap_designtree getDeviceMap() {
	return DeviceMap;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_DeviceMap(
	    org.testis.orm.classes.T_dmap_designtree value) {
	this.DeviceMap = value;
    }

    private org.testis.orm.classes.T_dmap_designtree getORM_DeviceMap() {
	return DeviceMap;
    }

    private void setORM_T_bed_dut(java.util.Set value) {
	this.ORM_t_bed_dut = value;
    }

    private java.util.Set getORM_T_bed_dut() {
	return ORM_t_bed_dut;
    }

    public final org.testis.orm.classes.T_bed_dutSetCollection t_bed_dut = new org.testis.orm.classes.T_bed_dutSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_T_BED_DUT,
	    org.testis.orm.manager.ORMConstants.KEY_T_BED_DUT_ACTIVEFIRMWARE,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    private void setORM_T_dmap_designtree(java.util.Set value) {
	this.ORM_t_dmap_designtree = value;
    }

    private java.util.Set getORM_T_dmap_designtree() {
	return ORM_t_dmap_designtree;
    }

    public final org.testis.orm.classes.T_dmap_designtreeSetCollection t_dmap_designtree = new org.testis.orm.classes.T_dmap_designtreeSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_T_DMAP_DESIGNTREE,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_FIRMWARE,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    public String toString() {
	return toString(false);
    }

    public String toString(boolean idOnly) {
	if (idOnly) {
	    return String.valueOf(getId());
	} else {
	    StringBuffer sb = new StringBuffer();
	    sb.append("T_bed_firmware[ ");
	    sb.append("Id=").append(getId()).append(" ");
	    sb.append("Name=").append(getName()).append(" ");
	    if (getDevice() != null)
		sb.append("Device.Persist_ID=")
			.append(getDevice().toString(true)).append(" ");
	    else
		sb.append("Device=null ");
	    if (getDeviceMap() != null)
		sb.append("DeviceMap.Persist_ID=")
			.append(getDeviceMap().toString(true)).append(" ");
	    else
		sb.append("DeviceMap=null ");
	    sb.append("Description=").append(getDescription()).append(" ");
	    sb.append("T_bed_dut.size=").append(t_bed_dut.size()).append(" ");
	    sb.append("T_dmap_designtree.size=")
		    .append(t_dmap_designtree.size()).append(" ");
	    sb.append("]");
	    return sb.toString();
	}
    }

}
